package cn.broadmax.boot.oauth;

import cn.broadmax.boot.constant.ThirdAccountType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author jeff
 * @date 2020/6/25
 */
@Component
public class OauthLoginSelector {

    @Autowired
    private List<OauthLoginProvider> oauthLoginProviders;

    public OauthLoginProvider get(ThirdAccountType type){
        for(OauthLoginProvider provider : oauthLoginProviders){
            if(provider.getType() == type){
                return provider;
            }
        }
        return null;
    }

    @Bean
    public OauthLoginProvider createDefaultProvider(){
        return new DefaultOauthLoginProvider();
    }

}
